package com.itheima.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.tanhua.dubbo.mapper.BlackListMapper;
import com.itheima.tanhua.dubbo.mapper.UserInfoMapper;
import com.itheima.tanhua.model.domain.BlackList;
import com.itheima.tanhua.model.domain.UserInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@DubboService
public class BlackListApiImpl implements BlackListApi{

    @Autowired
    private BlackListMapper blackListMapper;

    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * 黑名单分页查询
     * @param userId
     * @param page
     * @param pagesize
     * @return
     */
    @Override
    public Page<UserInfo> blackList(Long userId,Integer page, Integer pagesize) {
        //查询黑名单人员id
        LambdaQueryWrapper<BlackList> lqw = new LambdaQueryWrapper<>();
        lqw.eq(BlackList::getUserId,userId);
        List<BlackList> blackLists = blackListMapper.selectList(lqw);


        List<Long> list = new ArrayList();
        for (int i = 0; i < blackLists.size(); i++) {
          list.add(blackLists.get(i).getBlackUserId());
        }

        //根据黑名单人员id查询黑名单人员的详细信息
        LambdaQueryWrapper<UserInfo> userLqw = new LambdaQueryWrapper<>();
        userLqw.in(UserInfo::getId,list);

        Page<UserInfo> blackListPage = new Page<>(page,pagesize);
        userInfoMapper.selectPage(blackListPage,userLqw);


        return blackListPage;
    }
}
